package com.itheima.reggie.controller;

import com.itheima.reggie.commom.ResultInfo;
import com.itheima.reggie.domain.Address;
import com.itheima.reggie.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Sea
 * @date 2023/3/9 14:32
 */
@RestController
public class AddressController {
    @Autowired
    private AddressService addressService;
    //查询收获地址列表
    @GetMapping("/address/list")
    public ResultInfo list(){
    List<Address>list= addressService.list();
    return ResultInfo.success(list);
    }
    //新增收获地址
    @PostMapping("/address")
    public ResultInfo add(@RequestBody Address address){
        addressService.add(address);
        return ResultInfo.success();
    }
    //修改默认地址
    @PutMapping("/address/default")
    public ResultInfo put(@RequestBody Address address){
        addressService.put(address);
        return ResultInfo.success();
    }
    // 查询默认地址
    @GetMapping("/address/default")
    public ResultInfo findDefault(){
        Address address = addressService.findDefault();
        return ResultInfo.success(address);
    }
    // 回显收货地址
    @GetMapping("/address/{id}")
    public ResultInfo selectAddress(@PathVariable Long id) {
        Address address = addressService.selectAddress(id);
        return ResultInfo.success(address);
    }
    // 修改收货地址
    @PutMapping("/address")
    public ResultInfo saveAddress(@RequestBody Address address) {
        addressService.saveAddress(address);
        return ResultInfo.success();
    }

}